<?php
session_start();					// 启用Session
require 'db_connect.php';           // 连接数据库
$username = $_SESSION["username"];	// 获取Session中的用户名
$mail = $_POST["mail"];	            // 获取表单中修改之后的邮箱
$code = $_POST["code"];			    // 获取表单中的验证码

//维护一个验证码正确值和验证码图片下标的映射
$checks = ["pupr", "khrb", "huks", "egwb", "ekdv", "khns", "wuxc", "tcyk", "nupf", "brpk"];
$correct_code = $checks[$_SESSION["code"]];

if ($code == $correct_code) {
    $sql = "update users set mail = '$mail' where username = '$username'";   // 查询输入用户名和密码是否存在数据库中
    $result = $conn->query($sql);   // 执行更新语句
    $conn->close();                             // 关闭数据库连接
    $_SESSION["mail"] = $mail;
    header("Location: pannel.php");								// 跳转到用户面板
} else echo "验证码不正确！";											// 错误提示
?>